// 原材料出库-退料查询-zhangx
import React, { Component } from 'react'
import {ListBox} from '../../../components'
import { Modal } from 'antd';
import UpdateWorkareaPage from './UpdateNew'
import { fetchData } from '../../../components/AjaxConsumer'

export default class RawBackPage extends Component{
    constructor(props) {
        super(props);
        //行操作列表-已弃用
        this.rowOperation = [
            
        ];
        //header 操作列表111
        this.headerOperation = [
            {
                handleName: 'modifyPE',
                showName: '修改退料长度',
                iconClass: 'edit',
                permission: 'rawback-edit'
            }
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        // foreverHidden永久隐藏
        this.tableColumn = {
            storageKey: 'ListRawBackColumnConfig',
            data: [
                {
                    showName: 'id',
                    columnName: 'backId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '领料单号',
                    columnName: 'userDefined1',
                    columnWidth: 120
                },
                {
                    showName: '合同编号',
                    columnName: 'contractNo',
                    columnWidth: 120
                },{
                    showName: '条码',
                    columnName: 'barcode',
                    columnWidth: 120
                },{
                    showName: '型号',
                    columnName: 'model'
                },{
                    showName: '型号描述',
                    columnName: 'modelDesc'
                },{
                    showName: '型号类型',
                    columnName: 'modelType'
                },{
                    showName: '单位',
                    columnName: 'unit'
                },{
                    showName: '原数量',
                    columnName: 'oldAmount'
                },{
                    showName: '数量',
                    columnName: 'amount'
                },{
                    showName: '库位',
                    columnName: 'wlCode'
                },{
                    showName: '扫描人',
                    columnName: 'createBy',
                },{
                    showName: '扫描时间',
                    columnName: 'gmtCreate',
                    columnWidth: 135
                }
            ]
        };

        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        this.searchComponentData = [
            {
                name:'modelType',
                type: 'select',
                optionList:[]
            },{
                name:'amount',
                type: 'number',
                maxName:'amountMax', //最大值， 选择小于时使用；选择范围时大值使用
                minName:'amountMin'  //最小值， 选择大于时使用；选择范围时小值使用
            },{
                name:'oldAmount',
                type: 'number',
                maxName:'oldAmountMax', //最大值， 选择小于时使用；选择范围时大值使用
                minName:'oldAmountMin'  //最小值， 选择大于时使用；选择范围时小值使用
            },{
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax', //最大值， 选择小于时使用；选择范围时大值使用
                minName:'gmtCreateMin'  //最小值， 选择大于时使用；选择范围时小值使用
            },{
                name:'gmtModified',
                type: 'date',
                maxName:'gmtModifiedMax', 
                minName:'gmtModifiedMin'
            }
        ];

    }

    // 行操作
    rowHandles = (strHandles, rowObj) => {
        if (strHandles == 'modifyPE') {
            this.modifyPEHandles(rowObj);
        }
    }

    modifyPEHandles = (rowObj) => {
        if (rowObj.length == 0) {
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
            return;
        } else if (rowObj.length > 1) {
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
            return;
        } else if (rowObj[0].data.modelType != 'PE') {
            Modal.error({
                title: '错误提示',
                content: '只能修改PE管退料长度！',
            });
        } else {
            this.refs.updateWorkarea.editHandle(rowObj);
        }
    }

    componentWillMount() {
        const dicType = 'model_type';
        const options= {
            url: '/base/dic/get/' + dicType,
            type: 'get',
            condition:{}
        };
        //型号类型select
        fetchData(this, options, this.dicInitCallBackHandle);
    }

    //下拉框 初始化
    dicInitCallBackHandle = (resData)=>{
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = e.dicCode;
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });
        this.tableColumn.data[5].showOption = optionList;
        this.searchComponentData[0].optionList = optionList;
    }

    //刷新列表
    refreshHandle = () => {
        this.refs.rawBackList.refreshHandle();
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <div>
                <ListBox
                    ref = 'rawBackList'
                    title="原材料退料查询"
                    isHideLeft={isHideLeft}
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url = '/material/outwarehouse/rawback/list'
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    headerOperation = {this.headerOperation}
                    isRowSingle = "true"
                />
                
                <UpdateWorkareaPage
                    ref="updateWorkarea"
                    refreshHandle={this.refreshHandle}
                />
            </div>
        )
    }

}
